package CTRLayer;
import ModelLayer.*;
/**
 * A class to control the creation and management of products.
 * 
 * @author Mike M. Madsen, Rasmus A. Borup
 * @version 15/12-2013
 */
public class ProductCtr
{
    //Instance variables
    private ProductContainer products;
    
    /**
     * Constructor for objects of class ProductCtr
     */
    public ProductCtr()
    {
        products = ProductContainer.getInstance();
    }
    
    /**
     * Create a new product with the createProduct method and adds it to the product container
     */
    public void addProduct(int productID, String productName, String productDesc, String EAN, int productGroup, int amountInStock, double price, double discount)
    {
        Product product = createProduct(productID, productName, productDesc, EAN, productGroup, amountInStock, price, discount);
        products.addProduct(product);
    }
    
    /**
     * Creates a new Product object
     */
    public Product createProduct(int productID, String productName, String productDesc, String EAN, int productGroup, int amountInStock, double price, double discount)
    {
        return new Product(productID, productName, productDesc, EAN, productGroup, amountInStock, price, discount);
    }
    
    /**
     * Returns a product found in the product container determined by product name
     */
    public Product findProductByKeyWord(String keyWord)
    {
        Product foundProduct = products.findProductByKeyWord(keyWord);
        return foundProduct;
    }
    
    /**
     * Returns a product found in the product container determined by product id
     */
    public Product findProductByID(int searchID)
    {
        Product foundProduct = products.findProductByID(searchID);
        return foundProduct;
    }
    
    /**
     * Returns a product found in the product container determined by product EAN
     */
    public Product findProductByEAN(String searchEAN)
    {
        return products.findProductByEAN(searchEAN);
    }
    
    /**
     * Finds a product in the product container determined by product EAN and prints details about it
     */
//     public void listProductInfo(String searchEAN)
//     {
//         findProductByEAN(searchEAN).printInfo();
//     }
    
    /**
     * Changes the details of a product in the product container determined by product EAN 
     */
    public void updateProduct(String searchEAN, String productName, String productDesc, String EAN, int productGroup, int amountInStock, double price, double discount)
    {
        Product productToChange = products.findProductByEAN(searchEAN);
        {
            productToChange.setProductName(productName);
            productToChange.setProductDesc(productDesc);
            productToChange.setEAN(EAN);
            productToChange.setProductGroup(productGroup);
            productToChange.setAmountInStock(amountInStock);
            productToChange.setPrice(price);
            productToChange.setDiscount(discount);
        }
    }
    
    /**
     * Removes a product from the product container and returns a string telling whether it was removed or not
     */
    public String deleteProduct(int searchID)
    {
        if (products.deleteProduct(searchID))
        {
            return "Product removed!";
        }
        else
        {
            return "Product not found, and therefore not deleted!";
        }
    }
}
